package com.kwt.learn.multithread;

import java.util.stream.IntStream;

/**
 * ThreadLocal用法上比较简单，每个线程可以设置以一个私有的变量到ThreadLocal
 */
public class ThreadLocalTest01 {

    public static void main(String[] args) {
        ThreadLocal threadLocal = new ThreadLocal();
        threadLocal.set(1000);


        IntStream.range(0, 5).forEach(e -> new Thread(() -> {
            threadLocal.set(e);
            System.out.println("线程和local值分别是  " + e + ",     " + threadLocal.get());
        }).start());
    }
}
